﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Shapes;
using DBLibrary;

namespace WPFClient
{
    /// <summary>
    /// Logique d'interaction pour Login.xaml
    /// </summary>
    public partial class Login : Window
    {
        private Customer customer;

        public Login()
        {
            InitializeComponent();
            customer = new Customer();
        }

        private void buttonConnection_Click(object sender, RoutedEventArgs e)
        {
            customer.connect(textBoxLogin.Text, textBoxPassword.Password);
            if (!customer.IsConnected)
            {
                MessageBox.Show("Authentification non valide, vérifiez votre login et mot de passe.",
                    "Authentification invalide", MessageBoxButton.OK, MessageBoxImage.Warning);
                textBoxLogin.Text = "";
                textBoxPassword.Password = "";
            }
            else
            {
                MainWindow window = new MainWindow(customer);
                App.Current.MainWindow = window;
                this.Close();
                window.Show();
            }
        }

        private void buttonRegister_Click(object sender, RoutedEventArgs e)
        {
            Register registerWindow = new Register();
            App.Current.MainWindow = registerWindow;
            this.Close();
            registerWindow.Show();
        }
    }
}
